package com.sskj.fabi.ui.activity;


import android.support.v4.app.Fragment;
import android.support.v4.content.ContextCompat;
import android.widget.TextView;

import com.alibaba.android.arouter.facade.annotation.Route;
import com.alibaba.android.arouter.launcher.ARouter;
import com.sskj.common.adapter.MyFragmentPagerAdapter;
import com.sskj.common.base.App;
import com.sskj.common.util.ClickUtil;
import com.sskj.common.widget.ViewPagerSlide;
import com.sskj.fabi.R;
import com.sskj.fabi.R2;
import com.sskj.fabi.presenter.FabiOrderRecordActivityPresenter;
import com.sskj.lib.Constans;
import com.sskj.lib.RConfig;
import com.sskj.lib.base.BaseActivity;

import java.util.ArrayList;

import butterknife.BindView;

@Route(path = RConfig.FABI_ORDER_RECORD)
public class FabiOrderRecordActivity extends BaseActivity<FabiOrderRecordActivityPresenter> {
    @BindView(R2.id.tvBuy)
    TextView tvBuy;
    @BindView(R2.id.tvSell)
    TextView tvSell;
    @BindView(R2.id.viewPager)
    ViewPagerSlide viewPager;
    boolean isBuy = true;

    @Override
    protected int getLayoutResId() {
        return R.layout.fabi_activity_fabi_order_record;
    }

    @Override
    public FabiOrderRecordActivityPresenter getPresenter() {
        return new FabiOrderRecordActivityPresenter();
    }

    @Override
    protected void initView() {
        ClickUtil.click(tvBuy, () -> {
            if (!isBuy) {
                changeBuy();
            }
        });
        ClickUtil.click(tvSell, () -> {
            if (isBuy) {
                changeSell();
            }
        });

        viewPager.setSlide(false);
        ArrayList<Fragment> fragments = new ArrayList<>();
        fragments.add((Fragment) ARouter.getInstance().build(RConfig.FABI_FRAGMENT_ORDER_RECORD).withBoolean(Constans.IS_BUY, true).navigation());
        fragments.add((Fragment) ARouter.getInstance().build(RConfig.FABI_FRAGMENT_ORDER_RECORD).withBoolean(Constans.IS_BUY, false).navigation());
        viewPager.setAdapter(new MyFragmentPagerAdapter(getSupportFragmentManager(), fragments));
        if (isBuy) {
            changeBuy();
        } else {
            changeSell();
        }
    }

    private void changeSell() {
        isBuy = false;
        tvSell.setTextColor(ContextCompat.getColor(App.INSTANCE, R.color.commonWhite));
        tvBuy.setTextColor(ContextCompat.getColor(App.INSTANCE, R.color.fabi_bfa));
        viewPager.setCurrentItem(1);
    }

    private void changeBuy() {
        isBuy = true;
        tvBuy.setTextColor(ContextCompat.getColor(App.INSTANCE, R.color.commonWhite));
        tvSell.setTextColor(ContextCompat.getColor(App.INSTANCE, R.color.fabi_bfa));
        viewPager.setCurrentItem(0);
    }

}
